JSTL - SQL-Tags

SQL-Tags

 

 
coding-zon-JSTL-SQL-Tags

JSPHome


 
 
 
query.html

<html>  
<body>  

<form  method=post  action="query.jsp">  
<textarea    name='area1'    rows=10  cols=30>  
</textarea>  
<input  type=submit>  
</form> 
 
</body>  
</html>

query.jsp is given below. In the standard JDBC code, we begin by asking for the availability of the driver. "jdbc.odbc.JdbcOdbcDriver". And then, we specify the URL of the database as 'jdbc:odbc:telephone'.


Similarly, in JSTL also, we begin with SQL.

<sql:setDataSource tag.
var 
driver
url 


<c:set var="s"  value="${param.area1}"  />

<c:out value="${s}" />


'<sql:query'  tag, takes  three attributes., such as, symbolic name:   

 var="query1" datasource="${db} sql="${s}


 query.jsp

 

<%@ taglib    prefix="c" %>uri="http://java.sun.com/jstl/core"  
<%@ taglib    prefix="sql" %> uri="http://java.sun.com/jstl/sql"  

<html>  
<body>  

<sql:setDataSource var="db" 
      driver="sun.jdbc.odbc.JdbcOdbcDriver" 
      url="jdbc:odbc:dbdemo"  />  
<c:set var='s' value="${param.area1}" />  
<c:out value="${s}" />  <br>  

<sql:query   var="query1" dataSource="${db}" sql="${s}" />   
</sql:query>  
<table border="1">  
  <c:forEach var="row" items="${query1.rows}" >  
 <tr> 
    <td> <c:out value="${row.name}" /></td> 
    <td> <c:out value="${row.place}" /></td>  
 </tr>  
 </c:forEach>  
</table>  
</body>  
</html>

dbeditor.jsp
 

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"  %>  
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/sql"  %>  

<html>  
<body>  
<sql:setDataSource var="db" 
      driver="sun.jdbc.odbc.JdbcOdbcDriver" 
      url="jdbc:odbc:dbdemo"  />

<c:set     var='a'   value='${param.text1}' />  
<c:set     var='b'   value='${param.text2}' />  
<c:set     var='c'   value='${param.text3}' />  
<c:set     var='d'   value='${param.combo1}'/> 
 
<c:if test="${d == 'add'}" > <sql:update var="query1" dataSource="${db}" sql="insert into table1 values${a}','${b}')" > </sql:update> <c:out value="record added"/> </c:if>
<c:if test="${d == 'delete'}" > <sql:update var="query1" dataSource="${db}" sql="delete from table1 where name='${a}'" > </sql:update> <c:out value="record deleted"/> </c:if>
 
<c:if test="${d == 'modify'}" > <sql:update var="query1" dataSource="${db}" sql="update table1 set table1.name='${a}', table1.place='${b}' where table1.name='${c}'" > <--sql should be typed in a single line --> </sql:update> <c:out value="record modified"/> </c:if> <c:if test="${d == 'verify'}" > <sql:query var="query1" dataSource="${db}" sql="select * from table1 where name='${a}'" > </sql:query> <table border="1"> <c:forEach var="row" tems="${query1.rows}" > <c:set var="n" value="OK" /> <tr> <td> <c:out value="${row.name}" /></td> <td> <c:out value="${row.place}" /></td> </tr> </c:forEach> <c:if test="${n != 'OK'}" > <c:out value="No such Records" /> </c:if> </table> </c:if> </html> <body>

 

Comments

Popular posts from this blog

Using javascript pass form variables to iframe src

Creating a new PDF by Merging PDF documents using TCPDF

Import excel file into mysql in PHP